﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_MailGetCompleteInfo_V2]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_MailGetCompleteInfo_V2];
GO
-------------------------------------------------------------------------------
-- sproc_MailGetBriefInfo
-------------------------------------------------------------------------------
CREATE PROCEDURE [dbo].[sproc_MailGetCompleteInfo_V2]
    @MailID int
AS
BEGIN

-- Mark the read flag
UPDATE dbo.TabMailList SET MailReadFlag = 1 WHERE MailId = @MailID;

-- Return the full info of the mail
SELECT
	MailID,
	(SELECT RealName FROM dbo.UDS_Staff A WHERE A.Staff_Name = MailSender) as MailSender,
	(SELECT RealName FROM dbo.UDS_Staff A WHERE A.Staff_Name = MailReceiver) as MailReceiver,
	MailSendDate,
	MailSubject,
	MailBccToAddr,
	MailCcToAddr,
	MailBody,
	MailReadFlag,
	MailReceiverStr,
	MailSender,
	(SELECT ClassName FROM dbo.UDS_Class C WHERE C.Classid = M.ClassID) as classname
FROM dbo.TabMailList M
WHERE MailID = @MailID

END
GO
